// colorizer.v - colorizer module for video subsystem
//
// Copyright Aditya Joshi, Ajunja Vaidya(2014)
// 
// Created By:		Aditya Joshi, Anuja Vaidya
// Last Modified:	28-Apr-2014 (AJ)
//
// Description:
// ------------
// This module takes 2 pixel streams as input. World_pixel and icon_pixel stream.
// based on value of icon_pixel, it decides output stream 

module colorizer(
	input clock, rst,
	input [1:0] world_pixel,		// pixel stream with world map data
	input [1:0] icon_pixel,			// pixel stream with icon data
	input video_on,					// signal indicating blanking interval
	output reg [2:0] vgaRed,		// red color output to graphics VGA display
	output reg [2:0] vgaGreen,		// green color output to graphics VGA display
    output reg [2:1] vgaBlue		// blue color output to graphics VGA display
);

always @(posedge clock or posedge rst)
begin	
	
	if(rst) begin 							// on reset, all outputs are white
		vgaRed <= 3'b111;
		vgaGreen <= 3'b111;
		vgaBlue <= 2'b11;
	end
	else if(video_on == 0) begin			// during blanking interval, output black color
		vgaRed <= 3'b000;
		vgaGreen <= 3'b000;
		vgaBlue <= 2'b000;		
	end
	else begin
		if(video_on) begin
			case(icon_pixel[1:0])
				2'b00	:	begin 											// icon is transparent => display world in background
								case(world_pixel[1:0])
									2'b00	:	begin						// background in white color
													vgaRed <= 3'b111;
													vgaGreen <= 3'b111;
													vgaBlue <= 2'b11;
												end
									2'b01	:	begin						// black line
													vgaRed <= 3'b000;
													vgaGreen <= 3'b000;
													vgaBlue <= 2'b00;
												end
									2'b10	:	begin						// obstruction in red color
													vgaRed <= 3'b111;
													vgaGreen <= 3'b000;
													vgaBlue <= 2'b00;
												end
									2'b11	:	begin						// reserved 
													vgaRed <= 3'b000;
													vgaGreen <= 3'b000;
													vgaBlue <= 2'b00;
												end
											
									endcase
							end
				2'b01	:	begin 								// blue color
								vgaRed <= 3'b000;
								vgaGreen <= 3'b000;
								vgaBlue <= 2'b11;
							end
				2'b10	:	begin 								// red color 
								vgaRed <= 3'b111;
								vgaGreen <= 3'b00;
								vgaBlue <= 2'b00;
							end
				2'b11	:	begin  								// yellow color
								vgaRed <= 3'b111;
								vgaGreen <= 3'b111;
								vgaBlue <= 2'b00;
							end
			endcase
		end
	end

end
endmodule